/**
 *
 * Copyright Pact Lab of H.I.T.
 *
 * Designed and Implemented by Grid Researching Group, 
 * Pact Lab, Harbin
 * 
 * This Project is part of the national 973 Project:
 * Internet Based Virtual Computing Environment
 *
 * http://pact518.hit.edu.cn
 * 
 * Author:       Meteor <meteorlxk@gmail.com> 
 * Copyright:    pact518 
 * Version:      1.0
 * Created:      2009-4-20 
 * LastModified: 2009-4-20
 */
package edu.hit.pact.pgse.client;

import java.io.FileNotFoundException;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.SocketAddress;
import java.util.zip.DataFormatException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.hit.pact.pgse.client.handler.ClientMasterHandler;
import edu.hit.pact.pgse.communication.CommUtil;
import edu.hit.pact.pgse.timer.ClientTaskScheduler;
import edu.hit.pact.pgse.util.Globals;

/**
 * @author Meteor
 *
 */
public class ClientMainControl {
	
	public ClientManager clientManager;
	
	public ClientMainControl() throws FileNotFoundException, DataFormatException{
		this(LogFactory.getLog(ClientMainControl.class));
	}
	
	public ClientMainControl(Log logger) throws FileNotFoundException, DataFormatException {
		this.clientManager = new ClientManager();
		ClientTaskScheduler clientTaskScheduler = new ClientTaskScheduler(clientManager);

		SocketAddress masterAddress = new InetSocketAddress(Globals.MASTER_ADDRESS_IP, Globals.MASTER_LISTEN_PORT_FOR_CLIENT);
		(new CommUtil(new ClientMasterHandler(clientManager))).setConnector(masterAddress);
		clientTaskScheduler.scheduleConfTask();
		//clientTaskScheduler.scheduleWebTask();
		clientTaskScheduler.scheduleBlogTask();
		//clientTaskScheduler.scheduleBbsTask();
	}
	
	public static void main(String args[]) throws FileNotFoundException, DataFormatException, MalformedURLException, InterruptedException {
		/*
		 * load log4j property.
		 */
		Globals.readLog4jProperties();
		new ClientMainControl();
	}
}
